home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1322 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: info.uah.edu!oreo!gbacon
  2. From: gbacon@oreo (Greg Bacon)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: GoTo equivalent in C ??
  5. Date: 13 Jan 1996 02:00:05 GMT
  6. Organization: The University of Alabama in Huntsville
  7. Message-ID: <4d73n5$88a@info.uah.edu>
  8. References: <4d67vm$e5h@masala.cc.uh.edu>
  9. NNTP-Posting-Host: oreo.aspire.cs.uah.edu
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. sukumar (sukku@menudo.uh.edu) wrote:
  13. : Hi,
  14. :     I have always thought about this. How do you get the effect of goto
  15. : in C without using "goto"?? For ex, if I have to check for an error in my
  16. : function for every computation I do, and then do some cleaning up, how do 
  17. : I do it. Here is an example:
  18.  
  19. [snip]
  20.  
  21. : I don't want to use goto. what alternatievs do I have.
  22. : Any ideas are greatly appreciated.
  23.  
  24. : -Srini.
  25.  
  26. There is no goof reason not to use goto _judiciously_.  (Note the qualifier
  27. to all you would-be holy war initiators!)  To quote the FAQ:
  28.  
  29.         "In the case of the goto statement, it has long been observed
  30.         that unfettered use of goto's quickly leads to unmaintainable
  31.         spaghetti code."
  32.  
  33. Ahh, the wisdom of those words.  However, a real programmer isn't afraid
  34. to use goto (when it doesn't threaten her job security :)  If you are
  35. so truly opposed to goto, then you can get the same effect with an
  36. extra variable like so:
  37.  
  38. int stay = 0;
  39.  
  40. while (stay == 0)
  41. {
  42.    if exit condition is true {
  43.       /* you would goto here */
  44.       stay++;
  45. }
  46.  
  47. The thing about the purely structured approach is that you have to design
  48. some pretty tight loops at times which cut into your speed efficiency.
  49. Here's something to think about: what machine language do you know of that
  50. doesn't have a JMP instruction?  People who adhere strictly to the principles
  51. of structured programming are just like those who say that humans aren't
  52. animals.  People are just as much animals as programming is about goto's.
  53.  
  54. Food for thought :)
  55. Greg
  56. --
  57. Greg Bacon <gbacon@cs.uah.edu>
  58. University of Alabama in Huntsville
  59. CS Department Systems Support Team
  60.